﻿
// ConsoleDialog.cpp: 实现文件
//

#include "stdafx.h"
#include "Console.h"
#include "ConsoleDialog.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define		CODE_CK_TYPE_ELEMENT		1
#define		CODE_CK_TYPE_SUBELEMENT		2
#define		CODE_CK_TYPE_ITEM			3

#define		CODE_CK_ELEMENT_SHIFT		0
#define		CODE_CK_SUBELEMENT_SHIFT	8
#define		CODE_CK_ITEM_SHIFT			16

//#define		MAKE_CK_CODE(e,s,i)	( | ((unsigned int)(e))| ((unsigned int)(s))| ((unsigned int)(i)))
#define		MAKE_CK_CODE(e,s,i)	(((unsigned int)(e)<<CODE_CK_ELEMENT_SHIFT)| ((unsigned int)(s)<<CODE_CK_SUBELEMENT_SHIFT)| ((unsigned int)(i))<<CODE_CK_ITEM_SHIFT)


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// ConsoleDialog 对话框



ConsoleDialog::ConsoleDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CONSOLE_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void ConsoleDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(ConsoleDialog, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_INIT_DATABASE, &ConsoleDialog::OnBtnInitDatabase)
	ON_BN_CLICKED(IDC_BTN_TEST, &ConsoleDialog::OnBnClickedBtnTest)
	ON_BN_CLICKED(IDC_BTN_TEST_MYSQL, &ConsoleDialog::OnBnClickedBtnTestMysql)
END_MESSAGE_MAP()


// ConsoleDialog 消息处理程序

BOOL ConsoleDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void ConsoleDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void ConsoleDialog::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR ConsoleDialog::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void ConsoleDialog::OnBtnInitDatabase()
{
	//// TODO: 在此添加控件通知处理程序代码
	//ADODB::_ConnectionPtr	pConnection;
	//HRESULT hr = pConnection.CreateInstance("ADODB.Connection");
	//if (FAILED(hr))
	//{
	//	AfxMessageBox("创建ADODB::_ConnectionPtr实例失败!");
	//	return;
	//}

	//CString strMdbPath = "E:\\Project\\Apps\\zChecker\\Data\\Database\\mdb\\zChecker.mdb";
	//CString strConn;
	//strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", strMdbPath);
	//hr = pConnection->Open(_bstr_t(strConn), "", "", ADODB::adModeUnknown);
	//if (FAILED(hr))
	//{
	//	return;
	//}

	////初始化ELEMENT数据库
	//ADODB::_RecordsetPtr pRecordset;
	//hr = pRecordset.CreateInstance("ADODB.Recordset");
	//if (FAILED(hr))
	//{
	//	pConnection->Close();
	//	pConnection->Release();
	//	return;
	//}

	//CString strSQL = "SELECT * FROM CK_ELEMENT";
	//pRecordset->Open((_bstr_t)strSQL, pConnection.GetInterfacePtr(), ADODB::adOpenDynamic, ADODB::adLockOptimistic, ADODB::adCmdText);

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "空间参考系", 1, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "大地基准", 1, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "坐标系统", 1, 1, 1, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "高程基准", 1, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "高程基准", 1, 2, 1, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "地图投影", 1, 3, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "投影参数", 1, 3, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "图幅分幅", 1, 3, 2, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "位置精度", 2, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "平面精度", 2, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "平面位置误差", 2, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "控制点坐标",  2, 1, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "几何位移",    2, 1, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "矢量接边",    2, 1, 4, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "影像接边",    2, 1, 5, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "配准",       2, 1, 6, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "高程精度", 2, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "等高距", 2, 2, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "等高注记点", 2, 2, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "等高线高程中误差", 2, 2, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "控制点高程", 2, 2, 4, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "高程中误差", 2, 2, 5, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "套合差", 2, 2, 6, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "同名格网高程值", 2, 2, 7, CODE_CK_TYPE_ITEM);
	//	}		
	//}
	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "属性精度", 3, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "分类正确性", 3, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "分类代码值", 3, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "影像解译分类", 3, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "属性正确性", 3, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "属性值", 3, 2, 1, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "完整性", 4, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "多余", 4, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "要素多余", 4, 1, 1, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "遗漏", 4, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "要素遗漏", 4, 2, 1, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "逻辑一致性", 5, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "概念一致性", 5, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "属性项", 5, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "数据集", 5, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "格式一致性", 5, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "数据归档", 5, 2, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "数据格式", 5, 2, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "数据文件", 5, 2, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "文件命名", 5, 2, 4, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "拓扑一致性", 5, 3, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "拓扑关系", 5, 3, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "重合", 5, 3, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "重复", 5, 3, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "相接", 5, 3, 4, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "闭合", 5, 3, 4, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "打断", 5, 3, 4, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "时间精度", 6, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "现势性", 6, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "原始资料", 6, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "成果数据", 6, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "影像/栅格质量", 7, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "分辨率", 7, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "地面分辨率", 7, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "扫描分辨率", 7, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "格网参数", 7, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "色彩模式", 7, 2, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "色彩失真", 7, 2, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "信息丢失", 7, 2, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "RGB值", 7, 2, 4, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "杂色面积", 7, 2, 5, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "影像特性", 7, 3, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "几何类型", 7, 3, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "几何异常", 7, 3, 2, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "表征质量", 8, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "几何表达", 8, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "几何类型", 8, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "几何异常", 8, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "地理表达", 8, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "要素取舍", 8, 2, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "图形概括", 8, 2, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "要素关系", 8, 2, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "方向特征", 8, 2, 4, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "符号", 8, 3, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "符号规格", 8, 3, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "符号配置", 8, 3, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "注记", 8, 4, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "注记规格", 8, 4, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "注记内容", 8, 4, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "注记配置", 8, 4, 3, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "整饰", 8, 5, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "内外廓整饰", 8, 5, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "内图廓线", 8, 5, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "公里网线", 8, 5, 3, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "经线网线", 8, 5, 4, CODE_CK_TYPE_ITEM);
	//	}
	//}

	////////////////////////////////////////////////////////////////////////////
	//AddCheckElement(pRecordset, "附件质量", 9, 0, 0, CODE_CK_TYPE_ELEMENT);
	//{//======================================================================
	//	AddCheckElement(pRecordset, "元数据", 9, 1, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "项错漏", 9, 1, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "内容错漏", 9, 1, 2, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "图历薄", 9, 2, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "内容错漏", 9, 2, 1, CODE_CK_TYPE_ITEM);
	//	}
	//	AddCheckElement(pRecordset, "附属文档", 9, 3, 0, CODE_CK_TYPE_SUBELEMENT);
	//	{//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//		AddCheckElement(pRecordset, "完整性", 9, 3, 1, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "正确性", 9, 3, 2, CODE_CK_TYPE_ITEM);
	//		AddCheckElement(pRecordset, "权威性", 9, 3, 3, CODE_CK_TYPE_ITEM);
	//	}
	//}

	//pConnection->Close();

	//AfxMessageBox("完成数据库初始化");

}


void ConsoleDialog::AddCheckElement(ADODB::_RecordsetPtr pRecordset, CString strName, unsigned int nElemCode, unsigned int nSubElemCode, unsigned int nItemCode, unsigned int nType)
{
	try
	{
		unsigned int code;
		code = MAKE_CK_CODE(0, 0, 1);
		code = MAKE_CK_CODE(0, 1, 0);
		code = MAKE_CK_CODE(nElemCode, nSubElemCode, nItemCode);
		CString strCode;
		//strCode.Format("000-%03d-%03d-%03d", nElemCode, nSubElemCode, nItemCode);
		strCode.Format("%03d-%03d-%03d", nElemCode, nSubElemCode, nItemCode);

		pRecordset->AddNew();
		pRecordset->PutCollect("CK_CODE", code);
		pRecordset->PutCollect("CK_SCODE", (_bstr_t)strCode);
		pRecordset->PutCollect("CK_NAME", (_bstr_t)strName);
		//pRecordset->PutCollect("CK_ENAME", (_bstr_t)strName);
		pRecordset->PutCollect("CK_TYPE", nType);

		pRecordset->Update();
	}
	catch (...)
	{
		TRACE0("添加失败");
	}

}

void ConsoleDialog::OnBnClickedBtnTest()
{
	// TODO: 在此添加控件通知处理程序代码
	const char* szPath = "E:\\Project\\Apps\\zChecker\\Data\\Database\\mdb\\zChecker.mdb";
	ck::ElementRepository* pElementRepository = ck::ElementRepository::GetInstance();
	int ret = pElementRepository->Open(szPath);
	if (ret != RC_SUCCESS)
	{
		AfxMessageBox("Failure");
	}
}

void ConsoleDialog::OnBnClickedBtnTestMysql()
{
	RESULTCODE rc = RC_FAILURE;
	ck::Connection* pConnection = NULL;
	ck::ConnectionFactory* pConnFactory = ck::ConnectionFactory::GetInstance();
	//pConnection = pConnFactory->CreateConnection(ck::ckDbMySQL);
	//rc = pConnection->Open("127.0.0.1", 3306, "zChecker", "root", "qwer1234", "ADOMySQL");
	//if (rc != RC_SUCCESS)
	//{
	//	AfxMessageBox("连接数据库失败");
	//}

	pConnection = pConnFactory->CreateConnection(ck::ckDbAccess);

	const char* szPath = "E:\\Project\\Apps\\zChecker\\Data\\Database\\mdb\\zChecker.mdb";
	rc = pConnection->Open(NULL, NULL, szPath, NULL, NULL);
	if (rc != RC_SUCCESS)
	{
		AfxMessageBox("连接数据库失败");
	}

	ck::ElementRepository* pElementRepository = NULL;
	ck::ElementRepositoryFactory* pElemRepositoryFactory = ck::ElementRepositoryFactory::GetInstance();
	pElementRepository = pElemRepositoryFactory->GetElementRepository(pConnection->GetDbType());
	pElementRepository->Open(pConnection);

	rc = pElementRepository->Initialize();
	if (rc != RC_SUCCESS)
	{
		AfxMessageBox("创建Element表示失败");
	}
	rc = pElementRepository->Populate();

}

//void ConsoleDialog::OnBnClickedBtnTestMysql()
//{
//	//RESULTCODE rc = RC_FAILURE;
//	//ck::Connection* pConnection = NULL;
//	//ck::ConnectionFactory* pConnFactory = ck::ConnectionFactory::GetInstance();
//	//pConnection = pConnFactory->CreateConnection(ck::ckDbAccess);
//
//	//const char* szPath = "E:\\Project\\Apps\\zChecker\\Data\\Database\\mdb\\zChecker.mdb";
//	//rc = pConnection->Open(NULL, NULL, szPath, NULL, NULL);
//	//if (rc != RC_SUCCESS)
//	//{
//	//	AfxMessageBox("连接数据库失败");
//	//}
//
//	//pConnection->Close();
//
//	RESULTCODE rc = RC_FAILURE;
//	ck::Connection* pConnection = NULL;
//	ck::ConnectionFactory* pConnFactory = ck::ConnectionFactory::GetInstance();
//	pConnection = pConnFactory->CreateConnection(ck::ckDbMySQL);
//	rc = pConnection->Open("127.0.0.1", 3306, "zChecker", "root", "qwer1234", "ADOMySQL");
//	if (rc != RC_SUCCESS)
//	{
//		AfxMessageBox("连接数据库失败");
//	}
//
//	
//
//	const char* szSQL = " create table CK_ELEMENT (ID integer auto_increment, CK_CODE INT, CH_SCODE VARCHAR(32), CK_NAME VARCHAR(32), CK_ENAME VARCHAR(32), CK_TYPE INT, CK_DESCRIPTION VARCHAR(256) primary key, key(ID))";
//	HRESULT hr = pConnection->Execute(szSQL);
//	if (FAILED(hr))
//	{
//		AfxMessageBox("失败");
//	}
//
//	pConnection->Close();
//}
